package com.bysj.sausys.controller.portal;

import com.bysj.sausys.beans.PageQuery;
import com.bysj.sausys.beans.PageResult;
import com.bysj.sausys.common.AssConst;
import com.bysj.sausys.common.JsonData;
import com.bysj.sausys.model.SysAss;
import com.bysj.sausys.service.ISysAssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 社团信息Controller
 *
 * @author WangZK
 */
@Api(description = "社团信息接口")
@Controller
@RequestMapping("/ass")
public class AssController {

    @Resource
    private ISysAssService sysAssService;

    /**
     * 根据社团类别分页获取社团列表
     *
     * @param type
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "根据社团类别分页获取社团列表接口")
    @RequestMapping(value = "/getPageIsEnroll", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getPageIsEnroll(@ApiParam(value = "社团类别") @RequestParam(required = false) String type,
                                    @ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNo,
                                    @ApiParam(value = "每页显示条数") @RequestParam(required = false, defaultValue = "10") int pageSize) {
        PageResult result = sysAssService.getPageByTypeAndStatus(type, AssConst.ENROLL.getCode(), new PageQuery(pageNo, pageSize));
        return JsonData.success(result);
    }

    /**
     * 根据id获取社团信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取社团信息")
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getOne(@ApiParam(value = "社团id", required = true) @RequestParam Integer id) {
        SysAss sysAss = sysAssService.findById(id);
        return JsonData.success(sysAss);
    }

}
